<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        let arr = new Array(1, 2, 3, 4);
        /* 往头部添加元素,返回的是新数组的长度*/
        // let res = arr.unshift(9)
        // console.log(res,arr);

        Array.prototype.myUnShift = function (data) {
            //倒循环
            for (let i = this.length - 1; i >= 0; i--) {
                this[i+1] = this[i]
            }
            //处理第一个元素
            this[0] = data;
            return this.length 
        }
        let result = arr.myUnShift(9)
        console.log(result,arr);
    </script>
</body>

</html>